/*
 * Created on Feb 17, 2004
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package ModuleBuilder.model;

import javax.swing.*;

import ModuleBuilder.UI.*;
import ModuleBuilder.UI.tree.*;

/**
 * @author Milton  Soong
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 * 
 * This is a delegate that handles all the interactions between the different panels 
 * of the ModuleBuilder
 * 
 */
public class BuilderManager {
	PictureBuilder figureTopBuilder;
	PictureBuilder figureSideBuilder;
	PictureBuilder mapTileBuilder;
	GameParameter  gameParameter;
	MapBuilder	   mapBuilder;
	GameTreeEditor	   gameTreeEditor;
	
	public BuilderManager() {
	}

	/**
	 * @return
	 */
	public PictureBuilder getFigureSideBuilder() {
		return figureSideBuilder;
	}

	/**
	 * @return
	 */
	public PictureBuilder getFigureTopBuilder() {
		return figureTopBuilder;
	}

	/**
	 * @return
	 */
	public GameParameter getGameParameter() {
		return gameParameter;
	}

	/**
	 * @return
	 */
	public MapBuilder getMapBuilder() {
		return mapBuilder;
	}

	/**
	 * @param builder
	 */
	public void setFigureSideBuilder(PictureBuilder builder) {
		figureSideBuilder = builder;
	}

	/**
	 * @param builder
	 */
	public void setFigureTopBuilder(PictureBuilder builder) {
		figureTopBuilder = builder;
	}

	/**
	 * @param parameter
	 */
	public void setGameParameter(GameParameter parameter) {
		gameParameter = parameter;
	}

	/**
	 * @param builder
	 */
	public void setMapBuilder(MapBuilder builder) {
		mapBuilder = builder;
	}

	/**
	 * Call here when a new terrain piece has been added to the list
	 * Will 
	 * 1) figure out which image builder this came from,
	 * 2) call the corresponding builder to update it
	 * 
	 * @author Milton  Soong
	 *
	 * To change the template for this generated type comment go to
	 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
	 */
	public void imageAdded( JPanel src, ImageElement img ) {
		if ( src == mapTileBuilder ) {
			mapBuilder.mapTileAdded(img);
		} else if ( src == figureSideBuilder ) {
			gameTreeEditor.figureSideViewAdded(img);
		} else if ( src == figureTopBuilder ){
			gameTreeEditor.figureTopViewAdded(img);
		} else {		
			Debug.out("These imageAdded() calls have not been implemented yet.");
		}

	}
	
	/**
	 * call here when a map has been deleted
	 *
	 * To change the template for this generated type comment go to
	 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
	 */
	public void imageDeleted( JPanel src, ImageElement img ) {
		if ( src == mapBuilder ) {
			mapBuilder.mapTileDeleted(img);
		} else {
			Debug.out("These imageDeleted() calls have not been implemented yet.");
		}

	}
	/**
	 * @return
	 */
	public PictureBuilder getMapTileBuilder() {
		return mapTileBuilder;
	}

	/**
	 * @param builder
	 */
	public void setMapTileBuilder(PictureBuilder builder) {
		mapTileBuilder = builder;
	}

	public int getMapGridCol(){
		int val=GameParameter._initGridSize;
		if ( gameParameter != null ){
			val = gameParameter.getMapGridCol();
		}
		return ( val );
	}
	
	public int getMapGridRow(){
		int val=GameParameter._initGridSize;
		if ( gameParameter != null ){
			val = gameParameter.getMapGridRow();
		}
		return ( val );

	}
	
	public void mapSizeChanged() {
		mapBuilder.mapSizeChanged();
	}
	
	public void setGameTreeEditor ( GameTreeEditor in ) {
		gameTreeEditor = in;
	}
	/**
	 * @return
	 */
	public GameTreeEditor getGameTreeEditor() {
		return gameTreeEditor;
	}

}
